package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 *
 */
public enum Reject
        implements ByteBufferWritable {

    /**
     * 5: Reject call, facility rejected
     * 6: Reject call, channel unacceptable
     * 7: Reject call, incompatible destination
     * 8: Reject call, destination out of order
     * 0x34xx: The content of the low byte 'xx' will be signaled to
     * the network in a cause information element (octet 4). It is the
     * application's responsibility to provide a value that is properly
     * coded in accordance with Q.931/ETS 300 102-1. The controller
     * will send this cause value indicating coding standard
     * CCITT (octet 3).
     */

    /**
     * Accept call
     */
    ACCEPT(0),

    /**
     * Ignore call
     */
    IGNORE(1),

    /**
     * Reject call, normal call clearing
     */
    NORMAL_CALL_CLEARING(2),

    /**
     * Reject call, user busy
     */
    USER_BUSY(3),

    /**
     * Reject call, requested circuit/channel not available
     */
    REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE(4),

    FACILITY_REJECTED(5),

    CHANNEL_UNACCEPTABLE(6),

    INCOMPATIBLE_DESTINATION(7),

    DESTINATION_OUT_OF_ORDER(8),

    UNALLOCATED_NUMBER(0x3481);

    Reject(final int value) {
        _value = (short) value;
    }

    /**
     *
     * @return
     */
    public short getValue() {
        return _value;
    }

    private short _value;

    /** {@inheritDoc} */
    public void writeTo(final ByteBuffer byteBuffer) {
        byteBuffer.putShort(_value);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format("%s(0x%04x)",
                name(),
                getValue());

        return s;
    }

}
